package org.hhchat.leetcode.string;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class code500_easy {
    static class Solution {
        public String[] findWords(String[] words) {
            List<String> result = new ArrayList<>();
            String qstr = "qwertyuiop";
            String astr = "asdfghjkl";
            String zstr= "zxcvbnm";
            for(String word:words){
                if(word.length()==0){
                    result.add(word);
                    continue;
                }
                char c = word.toLowerCase().charAt(0);
                if(qstr.indexOf(c)>=0&&containsAll(qstr,word.toLowerCase())){
                    result.add(word);
                    continue;
                }
                if(astr.indexOf(c)>=0&&containsAll(astr,word.toLowerCase())){
                    result.add(word);
                    continue;
                }
                if(zstr.indexOf(c)>=0&&containsAll(zstr,word.toLowerCase())){
                    result.add(word);
                }
            }
            return result.toArray(new String[0]);
        }

        public boolean containsAll(String str, String chars){
            for(int i=1;i<chars.length();i++){
                if(str.indexOf(chars.charAt(i))<0){
                    return false;
                }
            }
            return true;
        }
    }

    public static void main(String[] args){
        Solution solution = new Solution();
        System.out.println(Arrays.toString(solution.findWords(new String[]{"sxadf", "Qwer"})));
    }

}
